package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllAuthoritiess", query = "select myAuthorities from Authorities myAuthorities"),
		@NamedQuery(name = "findAuthoritiesByAuthority", query = "select myAuthorities from Authorities myAuthorities where myAuthorities.authority = ?1"),
		@NamedQuery(name = "findAuthoritiesByAuthorityContaining", query = "select myAuthorities from Authorities myAuthorities where myAuthorities.authority like ?1"),
		@NamedQuery(name = "findAuthoritiesById", query = "select myAuthorities from Authorities myAuthorities where myAuthorities.id = ?1"),
		@NamedQuery(name = "findAuthoritiesByPrimaryKey", query = "select myAuthorities from Authorities myAuthorities where myAuthorities.id = ?1") })
@Table(catalog = "sow", name = "authorities")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "Authorities")
@XmlRootElement(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain")
public class Authorities implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "AUTHORITY", length = 50, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String authority;

	/**
	 */
	@OneToMany(mappedBy = "authorities", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<edu.hcmus.sow.domain.UserAuthorities> userAuthoritieses;
	/**
	 */
	@OneToMany(mappedBy = "authorities", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<edu.hcmus.sow.domain.GroupAuthorities> groupAuthoritieses;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setAuthority(String authority) {
		this.authority = authority;
	}

	/**
	 */
	public String getAuthority() {
		return this.authority;
	}

	/**
	 */
	public void setUserAuthoritieses(Set<UserAuthorities> userAuthoritieses) {
		this.userAuthoritieses = userAuthoritieses;
	}

	/**
	 */
	@JsonIgnore
	public Set<UserAuthorities> getUserAuthoritieses() {
		if (userAuthoritieses == null) {
			userAuthoritieses = new java.util.LinkedHashSet<edu.hcmus.sow.domain.UserAuthorities>();
		}
		return userAuthoritieses;
	}

	/**
	 */
	public void setGroupAuthoritieses(Set<GroupAuthorities> groupAuthoritieses) {
		this.groupAuthoritieses = groupAuthoritieses;
	}

	/**
	 */
	@JsonIgnore
	public Set<GroupAuthorities> getGroupAuthoritieses() {
		if (groupAuthoritieses == null) {
			groupAuthoritieses = new java.util.LinkedHashSet<edu.hcmus.sow.domain.GroupAuthorities>();
		}
		return groupAuthoritieses;
	}

	/**
	 */
	public Authorities() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Authorities that) {
		setId(that.getId());
		setAuthority(that.getAuthority());
		setUserAuthoritieses(new java.util.LinkedHashSet<edu.hcmus.sow.domain.UserAuthorities>(that.getUserAuthoritieses()));
		setGroupAuthoritieses(new java.util.LinkedHashSet<edu.hcmus.sow.domain.GroupAuthorities>(that.getGroupAuthoritieses()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("authority=[").append(authority).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Authorities))
			return false;
		Authorities equalCheck = (Authorities) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
